package state;

class Action{
  String str;
}

// 状态类
class ThreadState_{
    void move(Action input){

    }
    void run(){

    }
}
// 默认状态 他的状态在外部被修改 方法又在外部被调用。
class Thread_{
    ThreadState_ state;
    // 状态迁移
    void move(Action input){
        state.move(input);
    }
    //执行迁移后的状态
    void run(){
        state.run();
    }
}
// 创建状态
class NewState extends ThreadState_{
    private Thread_ t;
    public NewState(Thread_ t){this.t = t;}
    void move(Action input){
        // 迁移到R上来
        t.state = new R(t);
    }

    void run(){
        System.out.println(t);
        t.run();
    }

}

class R extends ThreadState_{
    private Thread_ t;
    public R(Thread_ t){this.t = t;}
    void move(Action input){

    }

    void run(){
        System.out.println(t);
    }
}

public class SateMch {
    public static void main(String[] args) {
        System.out.println("线程的状态机器");
        Thread_ s = new Thread_();
        System.out.println(s);
        NewState newState = new NewState(s);
        newState.move(new Action());
        newState.run();
    }
}
